package com.anlogic.sdk.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtils {
	
	public static String dateToString(String format, Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
	    return sdf.format(date);
	}
	
	public static Date stringToDate(String format, String dateString) {
		Date date = null;
		SimpleDateFormat sdf = new SimpleDateFormat(format);
	    try {
	    	date = sdf.parse(dateString);
		} catch (ParseException e) {
			return null;
		}
	    return date;
	}
	
	public static boolean isBefore(String format, String dateStr0, String dateStr1) {
		Date date0 = stringToDate(format, dateStr0);
		Date date1 = stringToDate(format, dateStr1);
		return date0.before(date1);
	}
	
	public static boolean isAfter(String format, String dateStr0, String dateStr1) {
		Date date0 = stringToDate(format, dateStr0);
		Date date1 = stringToDate(format, dateStr1);
		return date0.after(date1);
	}
}
